﻿using System;
using System.Collections.Generic;
using System.IO;

using System.Text;
using System.Web.UI.WebControls;


namespace Module.Core.Common
{
    public class ComomFunctions
    {
        public static void DeleteFile(string _Path)
        {
            if (File.Exists(_Path))
            {
                File.Delete(_Path);
            }
        }

        public static string GetWebContent(string Address)
        {
            string txOutput = "";
            if (Address != "")
            {
                System.Net.WebClient MyClient = new System.Net.WebClient();
                System.IO.Stream MyStream = MyClient.OpenRead(Address);
                System.IO.StreamReader MyStreamReader = new System.IO.StreamReader(MyStream);
                string NewLine;
                while ((NewLine = MyStreamReader.ReadLine()) != null)
                {
                    txOutput += NewLine + "\r\n";
                }
            }
            return txOutput;
        }

        public static void LoadDataRss(Repeater rpt,string linkRss )
        {
            try
            {
                //XDocument feedXml = XDocument.Load(Const.urlDantri + linkRss);

                //var feeds = from feed in feedXml.Descendants("item")
                //            select new
                //            {
                //                title = feed.Element("title").Value,
                //                //description = feed.Element("description").Value,
                //                link = feed.Element("link").Value.Replace(Const.urlDantri, "").Trim(),
                //                pubDate = feed.Element("pubDate").Value
                //            };

                //rpt.DataSource = feeds.Take(15);
                //rpt.DataBind();
            }
            catch (Exception)
            {
            }
        }

        public static string GetUrlXML(int lang, string folderSub, string fileXml)
        {
            if (folderSub == "")
                return System.Web.HttpContext.Current.Server.MapPath(Const.folderRoot + "/" + lang + "/" + fileXml + ".xml");
            else
                return System.Web.HttpContext.Current.Server.MapPath(Const.folderRoot + "/" + folderSub + "/" + lang + "/" + fileXml + ".xml");
        }

    }
}
